import type {
  CodeType,
  User,
  UserInfo,
  PatientList,
  Patient,
} from '@/types/user'
import { request } from '@/utils/request'

// 密码登录
// export const loginByPassword = (mobile: string, password: string) =>
//   request<User>('/login/password', 'POST', { mobile, password })

type loginReqData = { mobile: string; password: string }
export const loginByPassword = (data: loginReqData) => {
  return request<User>({
    method: 'POST',
    url: 'login/password',
    data,
  })
}

// 发送验证码
type sendMobile = { mobile: string; type: CodeType }
export const sendMobileCode = (data: sendMobile) => {
  return request({
    method: 'GET',
    url: 'code',
    data,
  })
}

type loginCode = { mobile: string; code: string }
export const loginByCode = (data: loginCode) => {
  return request<User>({
    method: 'POST',
    url: 'login',
    data,
  })
}

// 获取个人信息
export const getUserInfo = () => request<UserInfo>({ url: '/patient/myUser' })

// 获患者信息列表
export const getPatientList = () =>
  request<PatientList>({ url: '/patient/mylist' })

// 添加患者信息
export const addPatient = (patient: Patient) =>
  request({ url: '/patient/add', method: 'POST', data: patient })

// 编辑患者信息
export const editPatient = (patient: Patient) =>
  request({ url: '/patient/update', method: 'PUT', data: patient })

// 删除患者信息
export const delPatient = (id: string) =>
  request({ url: `/patient/del/${id}`, method: 'DELETE' })
